package com.ruoyi.project.modules.interfaceObject.service.impl;

import java.util.List;

import cn.hutool.core.collection.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.modules.interfaceObject.mapper.InterfaceObjectMapper;
import com.ruoyi.project.modules.interfaceObject.domain.InterfaceObject;
import com.ruoyi.project.modules.interfaceObject.service.IInterfaceObjectService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 接口对象关系Service业务层处理
 *
 * @author smallrain
 * @date 2021-11-04
 */
@Service
public class InterfaceObjectServiceImpl implements IInterfaceObjectService {
    @Resource
    private InterfaceObjectMapper interfaceObjectMapper;

    /**
     * 查询接口对象关系
     *
     * @param id 接口对象关系主键
     * @return 接口对象关系
     */
    @Override
    public InterfaceObject selectInterfaceObjectById(Long id) {
        return interfaceObjectMapper.selectInterfaceObjectById(id);
    }

    /**
     * 查询接口对象关系列表
     *
     * @param interfaceObject 接口对象关系
     * @return 接口对象关系
     */
    @Override
    public List<InterfaceObject> selectInterfaceObjectList(InterfaceObject interfaceObject) {
        return interfaceObjectMapper.selectInterfaceObjectList(interfaceObject);
    }

    /**
     * 新增接口对象关系
     *
     * @param interfaceObject 接口对象关系
     * @return 结果
     */
    @Override
    public int insertInterfaceObject(InterfaceObject interfaceObject) {
        return interfaceObjectMapper.insertInterfaceObject(interfaceObject);
    }

    /**
     * 修改接口对象关系
     *
     * @param interfaceObject 接口对象关系
     * @return 结果
     */
    @Override
    public int updateInterfaceObject(InterfaceObject interfaceObject) {
        return interfaceObjectMapper.updateInterfaceObject(interfaceObject);
    }

    /**
     * 批量删除接口对象关系
     *
     * @param ids 需要删除的接口对象关系主键
     * @return 结果
     */
    @Override
    public int deleteInterfaceObjectByIds(String ids) {
        return interfaceObjectMapper.deleteInterfaceObjectByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除接口对象关系信息
     *
     * @param id 接口对象关系主键
     * @return 结果
     */
    @Override
    public int deleteInterfaceObjectById(Long id) {
        return interfaceObjectMapper.deleteInterfaceObjectById(id);
    }

    @Override
    public boolean insertInterfaceObject(Long tableId, Long interfaceId, String objectType) {
        InterfaceObject interfaceObject = new InterfaceObject();
        interfaceObject.setObjectType(objectType);
        interfaceObject.setObjectId(tableId);
        interfaceObject.setInterfaceId(interfaceId);
        List<InterfaceObject> interfaceObjects = this.selectInterfaceObjectList(interfaceObject);
        if (!CollectionUtil.isNotEmpty(interfaceObjects)) {
            this.interfaceObjectMapper.insertInterfaceObject(interfaceObject);
            return true;
        }
        return false;
    }
}
